/**
 * 
 */
package com.demo.web.admin.service;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bluering.framework.FrameworkInvoker;
import com.bluering.framework.common.log.Logger;

/**
 * @author CaoHenghui
 *
 */
@Component
public class FrameworkInvokerUtil {
	
	private static Logger logger =Logger.getLogger(FrameworkInvokerUtil.class);
	
	private static FrameworkInvoker frameworkInvoker;
	
 	@Autowired
    public void setFrameworkInvoker(FrameworkInvoker frameworkInvoker) {
 		FrameworkInvokerUtil.frameworkInvoker = frameworkInvoker;
    }
 	
 	public static JSONObject invoke(String serviceCode,String version,Map<String,String> params) {
 		JSONObject json = null;
 		try {
 			Object obj = frameworkInvoker.invoke(serviceCode, version, params);
 	 		if(obj != null) {
 	 			json = JSON.parseObject(JSON.toJSONString(obj));
 	 		}
 		}catch(Exception e) {
 			logger.error(e.getMessage(),e);
 		}
 		return json;
 	}

}
